package ob_TakeNote;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * author: 伟字号
 * date: 2025/1/12
 * description: 读取md文件，并返回一个ArrayList<String>  
 * version: 1.0
 *
 */
public class Read_ob {
   private BufferedReader br;
   private ArrayList<String> list;


   public Read_ob(File textDirPath) throws Exception{
      this.br = new BufferedReader(new FileReader(textDirPath));
      this.list = new ArrayList<String>();
   }

public ArrayList<String> read_md() throws Exception {


   String line = null;
   while ((line = br.readLine()) != null) {
      list.add(line);
   }
   br.close();

//   // 创建一个新列表进行深拷贝
//   ArrayList<String> deepCopyList = new ArrayList<>();
//   for (String item : list) {
//      deepCopyList.add(new String(item)); // 这里使用new String()确保是新的对象
//   }


   return list;
}
public static ArrayList<String> read_md(File path) throws IOException {
   BufferedReader br=new BufferedReader(new FileReader(path));
   ArrayList<String> list = new ArrayList<String>();
   String line = null;
   while ((line = br.readLine()) != null) {
      list.add(line);
   }
   br.close();
   // 如果文件为空，返回null
   if (list.isEmpty()){return null;}

      return list;

}

}